package za.org.jcicada.comms.impl;

import za.org.jcicada.comms.IMessageListener;
import za.org.jcicada.comms.messages.CommsMessage;

/**
 * Abstract base implementation for message listeners which dispatches messages
 * to methods on this class or classes derived from it.
 * @author rcrida
 */
public abstract class MessageListenerBase implements IMessageListener {

    /**
     * Message handler for routing receive messages to methods
     * in the dispatcher.
     */
    JavaMessageHandler handler;
    
    /**
     * Constructor sets up message handler to dispatch messages to this class.
     */
    public MessageListenerBase() {
        handler = new JavaMessageHandler(this);
    }
    
    @Override
    public void onMessage(CommsMessage message) throws Exception {
        handler.process(message);
    }

}
